let app = getApp();
var util = require("../../utils/util.js");
var siteinfo = require('../../siteinfo.js');
Page({

  data: {
    isShare: false,
    shareResumeId: '',
    img: '/image/photo.png',
    region: '',
    switch1Checked: false,
    text: '已隐身',
    workImg: [],//工作照片
    imglist: [],
    headPortrait:'',
    resume: {
      educationExperience: '',
      workExperience: '',
      project: '',
      certificate: '',
      arr:'',
      arr1:''
    },
    region: ["", "", ""]
  },

  onLoad: function (options) {
    var resumeId = options.resumeId
    var _this = this
    if (resumeId == null || resumeId == '') {
      _this.setData({
        isShare: false
      })
      _this.getResume()
    } else {
      _this.setData({
        isShare: true,
        shareResumeId: resumeId
      })
      _this.getShareResume()
    }
    var time = util.formatTime(new Date());
    wx.showShareMenu({
      withShareTicket: true
    })
    _this.setData({
      nowDate: time.substring(0, 10),
    })
      _this.setData({
        id: options.id
      })
    
    _this.getResume()
  },

  onShow: function () {
    // this.getUserDetail()

  },
  /**
   * 获取分享的简历信息
   */
  getShareResume: function () {
    var _this = this
    app._get(siteinfo.selResumeUser, { id: _this.data.shareResumeId }, function (result) {
      if (result.data == null) {
        wx.showModal({
          title: '提示',
          content: '参数错误！',
          showCancel: false
        })
        return;
      }
      wx.setNavigationBarTitle({
        title: result.data.name + '的简历'
      })
      if (result.data.educationExperience != null)
        result.data.educationExperience = JSON.parse(result.data.educationExperience)
      if (result.data.workExperience != null)
        result.data.workExperience = JSON.parse(result.data.workExperience)
      if (result.data.project != null)
        result.data.project = JSON.parse(result.data.project)
      if (result.data.certificate != null)
        result.data.certificate = JSON.parse(result.data.certificate)
      result.data.imglist = JSON.parse(result.data.imglist)
      result.data.workImg = JSON.parse(result.data.workImg)
      let oldarr=result.data.arr 
      if(null!=oldarr && oldarr.indexOf(',，月嫂星级')>=0){
        result.data.arr=oldarr.substring(0,oldarr.indexOf(',，月嫂星级'))
        result.data.arr1=oldarr.substring(oldarr.indexOf(',，月嫂星级')+7,oldarr.length)  
      }
      let oldcharacter=result.data.character 
      if(null!=oldcharacter && oldcharacter.indexOf('性格特点：')>=0){
        result.data.character =oldcharacter.substring(5,oldcharacter.length)
      }
      _this.setData({
        resume: result.data,
        // imglist:imglist
      });
      _this.setData({
        age: util.getAge(result.data.age)
      });
    });
  },
  /**
 * 获取简历信息
 */
  getResume: function () {
    var _this = this
    app._get(siteinfo.recruimeDetails, { id: _this.data.id}, function (result) {
      if (result.data.educationExperience != null)
        result.data.educationExperience = JSON.parse(result.data.educationExperience)
      if (result.data.workExperience != null)
        result.data.workExperience = JSON.parse(result.data.workExperience)
      if (result.data.project != null)
        result.data.project = JSON.parse(result.data.project)
      if (result.data.certificate != null)
        result.data.certificate = JSON.parse(result.data.certificate)
        result.data.imglist = JSON.parse(result.data.imglist)
        result.data.workImg = JSON.parse(result.data.workImg)
        let oldarr=result.data.arr
        if(null!=oldarr && oldarr.indexOf(',，月嫂星级')>=0){
          result.data.arr=oldarr.substring(0,oldarr.indexOf(',，月嫂星级'))
          result.data.arr1=oldarr.substring(oldarr.indexOf(',，月嫂星级')+7,oldarr.length)  
        }
        let oldcharacter=result.data.character 
        if(null!=oldcharacter && oldcharacter.indexOf('性格特点：')>=0){
          result.data.character =oldcharacter.substring(5,oldcharacter.length)
        }
      _this.setData({
        resume: result.data,
        // imglist:image,
        // workImg:workimg
      });
     
      _this.setData({
        age: util.getAge(result.data.age)
      });
    });
  },

  // 预览图片
  previewImg: function (e) {
    var src = e.currentTarget.dataset.src;
    var imgList = e.currentTarget.dataset.list;
    wx.previewImage({
      current: src,
      urls: imgList
    })

  },
  previewImgs: function (e) {
    var src = e.currentTarget.dataset.src;
    var imgList = e.currentTarget.dataset.list;
    wx.previewImage({
      current: src,
      urls: imgList
    })
  },
  shareResume: function () {
    var _this = this
    wx.navigateTo({
      url: '/pages/myResume/myResume?resumeId=' + _this.data.resume.id,
    })
  },
  onShareAppMessage: function () {
    var _this = this
    return {
      title: _this.data.resume.name + '的简历',
      desc: _this.data.resume.name + '的简历',
      path: '/pages/myResume/myResume?resumeId=' + _this.data.resume.id // 路径，传递参数到指定页面。
    }
  }
})